package com.maven.springmvc.controller;


import com.maven.springmvc.model.MessageInfo;
import com.maven.springmvc.service.SubmitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/message")
public class MessageWallController {
    @Autowired
    SubmitService submitService;

    // 这里是看 提交是否成功
    @RequestMapping("/submit")
    public boolean submit(MessageInfo info) {
        if(!StringUtils.hasLength(info.getFrom())
                || !StringUtils.hasLength(info.getTo())
                || !StringUtils.hasLength(info.getMessage())){
            return false;
        }
        submitService.submit(info);
        return true;
    }


    // 这里是获取 以及提交的 数据
    @RequestMapping("/get")
    public List<MessageInfo> get() {
        for(MessageInfo info:submitService.getMessage()){
            System.out.println(info.toString());
        }
        return submitService.getMessage();
    }
}
